import QtQuick 2.15
import QtQuick.Controls 2.15
import './../../../controls'
//商品信息
CPopup {
    id: createTrackingDialog
    width: 800
    height: 600
    modal: true
    dim:true
    padding: 0
    property string bno: ''
    closePolicy: Popup.CloseOnPressOutside | Popup.CloseOnEscape
    property var orderInfo: null
    Component.onCompleted: {
        loadData()
    }

    function loadData()
      {
          var request = HttpHelper.createIMRequest();
        // request.enabledLog=true
          request.onSucceed( function(request){
              console.log('----water_device_get_orderinfo---',JSON.stringify(request.responseData))
              orderInfo=request.responseData
          } );
          request.onError(  function(request){
              CGlobal.showMessage(window,request.errorMessage)
          } );
          request.get("/sys/watpc/pc/water_device_get_orderinfo/"+bno)
      }
    Rectangle {
        id:root
        anchors.fill: parent
        // gradient: mainGradient
        Rectangle{
            width: 800
            height: root.height - parent.y - 100
            radius: 10
            Item {
                anchors.fill: parent
                anchors.margins: 20
                Rectangle {
                    width: parent.width
                    height: parent.height
                    Rectangle {
                        id:itemHeader
                        width: parent.width
                        anchors.horizontalCenter: parent.horizontalCenter
                        height: 30
                        color: '#F5F7FA'
                        property var itemWidth: width / 4
                        Row{
                            anchors.verticalCenter: parent.verticalCenter
                            height: parent.height
                            width: parent.width
                            Repeater{
                                model: [qsTr('图片'),qsTr('名称'),qsTr('价格'),qsTr('数量')]
                                Text {
                                    width: itemHeader.itemWidth
                                    height: itemHeader.height
                                    color: '#E0000000'
                                    horizontalAlignment: Text.AlignHCenter
                                    verticalAlignment: Text.AlignVCenter
                                    text: modelData
                                    elide: Text.ElideRight
                                    anchors.verticalCenter: parent.verticalCenter
                                }
                            }
                        }
                    }
                    ListView{
                        id:lvs
                        anchors.fill: parent
                        anchors.topMargin: itemHeader.height
                        model: {
                            if(orderInfo && 'cost' in orderInfo){
                                return orderInfo.cost
                            }
                            return []
                        }
                        ScrollBar.vertical: ScrollBar{}
                        clip: true
                        property var itemWidth: width / 4
                        property var itemHeight: 70
                        boundsBehavior: Flickable.StopAtBounds
                        delegate: Rectangle{
                            width: lvs.width
                            height: lvs.itemHeight
                            property var itemData: lvs.model[index]
                            color: index % 2 === 0 ? '#FFF2F2F2' : '#ffffff'
                            Row{
                                Item {
                                    width: lvs.itemWidth
                                    height: lvs.itemHeight
                                    Image {
                                        width: lvs.itemHeight - 10
                                        height: lvs.itemHeight - 10
                                        asynchronous: true
                                        smooth: true
                                        source: itemData.img
                                        anchors.centerIn: parent
                                    }
                                }
                                Text {
                                    width: lvs.itemWidth
                                    height: lvs.itemHeight
                                    color: '#333333'
                                    horizontalAlignment: Text.AlignHCenter
                                    verticalAlignment: Text.AlignVCenter
                                    text: itemData.name +' ' + itemData.specs
                                    elide: Text.ElideRight
                                    wrapMode: Text.WrapAnywhere
                                }
                                Text {
                                    width: lvs.itemWidth
                                    height: lvs.itemHeight
                                    color: '#333333'
                                    horizontalAlignment: Text.AlignHCenter
                                    verticalAlignment: Text.AlignVCenter
                                    text: itemData.price
                                    elide: Text.ElideRight
                                    wrapMode: Text.WrapAnywhere
                                }
                                Text {
                                    width: lvs.itemWidth
                                    height: lvs.itemHeight
                                    color: '#333333'
                                    horizontalAlignment: Text.AlignHCenter
                                    verticalAlignment: Text.AlignVCenter
                                    text: itemData.num
                                    elide: Text.ElideRight
                                    wrapMode: Text.WrapAnywhere
                                }

                            }
                        }
                    }
                }
            }
        }

    }

}
